package lib;


public class RectangleArea implements GeometricArea {

	public RectangleArea(CartesianPoint ll, CartesianPoint ur) {
		if (ll.getX() > ur.getX() || ll.getY() > ur.getY())
			throw new IllegalArgumentException("Invalid Cartesian Space: " + ll + ur);
		lowLeft = ll;
		upRight = ur;
	}


	/**
	 * Checks edge boundaries and returns true iff input point is within
	 * the boundary of this RectangleArea
	 */
	@Override
	public boolean contains(Point point, boolean edgeInclusive) {
		if (point.getDimensions() != 2)
			throw new IllegalArgumentException("Invalid Point Dimension: " + point.getDimensions());
		double x, y;
		x = point.getValue(0);
		y = point.getValue(1);
		if (edgeInclusive) {
			if (x < lowLeft.getX() || x > upRight.getX())
				return false;
			if (y < lowLeft.getY() || y > upRight.getY())
				return false;
		} else {
			if (x <= lowLeft.getX() || x >= upRight.getX())
				return false;
			if (y <= lowLeft.getY() || y >= upRight.getY())
				return false;
		}
		return true;
	}
	
	public CartesianPoint getLowLeft() {
		return lowLeft;
	}

	public CartesianPoint getUpRight() {
		return upRight;
	}
	
	public double getArea() {
		double area;
		double dx, dy;
		dx = (upRight.getX() - lowLeft.getX());
		dy = (upRight.getY() - lowLeft.getY());
		area = dx * dy;
		return area;
	}

	private CartesianPoint upRight;
	private CartesianPoint lowLeft;
}
